// 新增按钮
function add() {
    // 打开新增框架
    document.getElementById('addBlock').style.display = 'block';
    document.getElementById('totalBackground').style.display = 'block';
}

// 提交按钮
function sumbit(var1,var2,var3,var4,var5,var6,var7) {
    // 关闭新增框架

    document.getElementById('addBlock').style.display = 'none';
    document.getElementById('totalBackground').style.display = 'none';
    
    // 写入表单
    // 获取表
    var iTable = document.getElementById('myTable');
    // 获取输入值
    // var stuId = document.getElementById('stuId1').value;
    // var name = document.getElementById('name1').value;
    // var colg = document.getElementById('colg1').value;
    // var profession = document.getElementById('profession1').value;
    // var grade = document.getElementById('grade1').value;
    // var stuClass = document.getElementById('stuClass1').value;
    // var age = document.getElementById('age1').value;
    // var nums = iTable.rows.length;
    var stuId = var1;
    var name = var2;
    var colg = var3;
    var profession = var4;
    var grade = var5;
    var stuClass = var6;
    var age = var7;
    var nums = iTable.rows.length;
    // 创建一行tr
    var iTr = document.createElement('tr');
    // 隔行换色
    if (nums % 2 != 0)
    {
        iTr.className = 'mainTbodyTr1';
    }
    else {
        iTr.className = 'mainTbodyTr2';
    }

    // 将tr添加到table中
    iTable.appendChild(iTr);

    // 创建选择按钮
    var sel = document.createElement('input');
    sel.setAttribute('type','checkbox');
    sel.setAttribute('name','item');

    // 创建单元格td，并添加属性、内容
    var iTd1 = document.createElement('td');
    iTd1.className = "col1";
    iTd1.appendChild(sel);
    var iTd2 = document.createElement('td');
    iTd2.className = "col2";
    iTd2.appendChild(document.createTextNode(nums));
    var iTd3 = document.createElement('td');
    iTd3.className = "col3";
    iTd3.appendChild(document.createTextNode(stuId));
    var iTd4 = document.createElement('td');
    iTd4.className = "col4";
    iTd4.appendChild(document.createTextNode(name));
    var iTd5 = document.createElement('td');
    iTd5.className = "col5";
    iTd5.appendChild(document.createTextNode(colg));
    var iTd6 = document.createElement('td');
    iTd6.className = "col6";
    iTd6.appendChild(document.createTextNode(profession));
    var iTd7 = document.createElement('td');
    iTd7.className = "col7";
    iTd7.appendChild(document.createTextNode(grade));
    var iTd8 = document.createElement('td');
    iTd8.className = "col8";
    iTd8.appendChild(document.createTextNode(stuClass));
    var iTd9 = document.createElement('td');
    // iTd9.className = "col9";
    // iTd9.appendChild(document.createTextNode(age));
    iTd9.className = 'col9';
    var pictures = document.createElement('input');
    pictures.id = 'pictures'
    pictures.setAttribute('type','button');
    pictures.setAttribute('value','展示图片');
    pictures.setAttribute('onclick','picture(var7)');
    iTd9.appendChild(pictures);
    var iTd10 = document.createElement('td');
    iTd10.className = "col10";
    var examine = document.createElement('input');
    examine.id = 'examine';
    examine.setAttribute('type','button');
    examine.setAttribute('value','审核通过');
    examine.setAttribute('onclick','examine(var2)');
    var update = document.createElement('input');
    update.id = 'update';
    update.setAttribute('type','button');
    update.setAttribute('value','审核拒绝');
    update.setAttribute('onclick','update(var2)');
    iTd10.appendChild(examine);
    iTd10.appendChild(update);

    // 将单元格添加到行
    iTr.appendChild(iTd1);
    iTr.appendChild(iTd2);
    iTr.appendChild(iTd3);
    iTr.appendChild(iTd4);
    iTr.appendChild(iTd5);
    iTr.appendChild(iTd6);
    iTr.appendChild(iTd7);
    iTr.appendChild(iTd8);
    iTr.appendChild(iTd9);
    iTr.appendChild(iTd10);

    // 将新增框架中的输入框值初始化
    document.getElementById('stuId1').value = null;
    document.getElementById('name1').value = null;
    document.getElementById('colg1').value = null;
    document.getElementById('profession1').value = null;
    document.getElementById('grade1').value = null;
    document.getElementById('stuClass1').value = null;
    document.getElementById('age1').value = null;

    document.getElementById('nums').innerText = nums;

    var pageNum = document.getElementById('pageNum').innerText;
    pageNum = parseInt(pageNum);
    for (var i=10*pageNum+1; i<=nums; i++) {
        iTable.rows[i].style.display = 'none';
    }
}

// 新增中的取消按钮
function addCancel() {
    // 关闭新增框架
    document.getElementById('addBlock').style.display = 'none';
    document.getElementById('totalBackground').style.display = 'none';
}

function showRes()
{
    $.get("http://39.106.79.148:5000/control",function(data,status){
        var temp = data;
        var tab = document.getElementById('myTable');
        var rows=tab.rows;
        for(var i=0;i<rows.length;i++)
        {
        tab.deleteRow(rows[i]);
        i--;
        if(i<0) i=-1;
        }
        var table_head = document.getElementById('myTable').querySelector('thead');
        var table_head = table_head.appendChild(document.createElement('tr'));
        var col1 = document.createElement('th');
        col1.setAttribute('class','col1');
        var ins = document.createElement('input');
        ins.setAttribute('type','checkbox');
        ins.setAttribute('onclick','checkAll(this)');
        col1.appendChild(ins);
        var col2 = document.createElement('th');
        col2.setAttribute('class','col2');
        col2.innerHTML = '序号';
        var col3 = document.createElement('th');
        col3.setAttribute('class','col3');
        col3.innerHTML = 'houseType';
        var col4 = document.createElement('th');
        col4.setAttribute('class','col4');
        col4.innerHTML = 'houseName';
        var col5 = document.createElement('th');
        col5.setAttribute('class','col5');
        col5.innerHTML = 'userName';
        var col6 = document.createElement('th');
        col6.setAttribute('class','col6');
        col6.innerHTML = 'area';
        var col7 = document.createElement('th');
        col7.setAttribute('class','col7');
        col7.innerHTML = 'property';
        var col8 = document.createElement('th');
        col8.setAttribute('class','col8');
        col8.innerHTML = 'totalPrice';
        var col9 = document.createElement('th');
        col9.setAttribute('class','col9');
        col9.innerHTML = 'pictures';
        var col10 = document.createElement('th');
        col10.setAttribute('class','col10');
        col10.innerHTML = '操作';
        table_head.appendChild(col1);
        table_head.appendChild(col2);
        table_head.appendChild(col3);
        table_head.appendChild(col4);
        table_head.appendChild(col5);
        table_head.appendChild(col6);
        table_head.appendChild(col7);
        table_head.appendChild(col8);
        table_head.appendChild(col9);
        table_head.appendChild(col10);
        for(var i=0;i<temp.length;i++)
        {
            var1 = temp[i].home_out_type;
            var2 = temp[i].home_name;
            var3 = temp[i].name;
            var4 = temp[i].area;
            var5 = temp[i].property;
            var6 = temp[i].total_price;
            var7 = temp[i].picture;
            sumbit(var1,var2,var3,var4,var5,var6,var7);
        }
    }
      );
}
    // var temp = [
    //     {
    //         "id": 3,
    //         "home_out_type": "卖房",
    //         "name": "王世钢",
    //         "id_card": "112233",
    //         "home_name": "王世钢的房子",
    //         "home_type": "三室一厅",
    //         "floor": "第三层/共七层",
    //         "elevator": "1",
    //         "area": "88.88m2",
    //         "decorate": "精装",
    //         "picture": "http://p1.music.126.net/prPyfG75Tuo4X49tOTVzMQ==/109951165308931930.jpg?imageView&quality=89",
    //         "property": "私产",
    //         "toward": "朝南",
    //         "total_price": "10000刀",
    //         "rent_type": null,
    //         "unit_price": null,
    //         "rent_time": null,
    //         "rent_require": null,
    //         "home_situation": null,
    //         "home_verify": "未审核",
    //         "home_owner": "christina"
    //     },
    //     {
    //         "id": 4,
    //         "home_out_type": "卖房",
    //         "name": "222",
    //         "id_card": "112233",
    //         "home_name": "233的房子",
    //         "home_type": "三室一厅",
    //         "floor": "第三层/共七层",
    //         "elevator": "1",
    //         "area": "88.88m2",
    //         "decorate": "精装",
    //         "picture": "http://p1.music.126.net/prPyfG75Tuo4X49tOTVzMQ==/109951165308931930.jpg?imageView&quality=89",
    //         "property": "私产",
    //         "toward": "朝南",
    //         "total_price": "10000刀",
    //         "rent_type": null,
    //         "unit_price": null,
    //         "rent_time": null,
    //         "rent_require": null,
    //         "home_situation": null,
    //         "home_verify": "未审核",
    //         "home_owner": "christina"
    //     },
    //     {
    //         "id": 5,
    //         "home_out_type": "卖房",
    //         "name": "1234",
    //         "id_card": "112233",
    //         "home_name": "huhuhu的房子",
    //         "home_type": "三室一厅",
    //         "floor": "第三层/共七层",
    //         "elevator": "0",
    //         "area": "88.88m2",
    //         "decorate": "精装",
    //         "picture": "http://p1.music.126.net/prPyfG75Tuo4X49tOTVzMQ==/109951165308931930.jpg?imageView&quality=89",
    //         "property": "私产",
    //         "toward": "朝南",
    //         "total_price": "10000刀",
    //         "rent_type": null,
    //         "unit_price": null,
    //         "rent_time": null,
    //         "rent_require": null,
    //         "home_situation": null,
    //         "home_verify": "未审核",
    //         "home_owner": "christina"
    //     },
    //     {
    //         "id": 6,
    //         "home_out_type": "卖房",
    //         "name": "ooooo",
    //         "id_card": "112233",
    //         "home_name": "呼呼呼的房子",
    //         "home_type": "三室一厅",
    //         "floor": "第三层/共七层",
    //         "elevator": "0",
    //         "area": "88.88m2",
    //         "decorate": "精装",
    //         "picture": "http://p1.music.126.net/prPyfG75Tuo4X49tOTVzMQ==/109951165308931930.jpg?imageView&quality=89",
    //         "property": "私产",
    //         "toward": "朝南",
    //         "total_price": "10000刀",
    //         "rent_type": null,
    //         "unit_price": null,
    //         "rent_time": null,
    //         "rent_require": null,
    //         "home_situation": null,
    //         "home_verify": "未审核",
    //         "home_owner": "christina"
    //     }
    // ];
